package com.example.zwh.computershop.shopping_cart;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.zwh.computershop.R;
import com.example.zwh.computershop.handleDataClient.handleData;

import java.util.List;

import static android.content.ContentValues.TAG;

public class ShopOrderAdapter extends RecyclerView.Adapter<ShopOrderAdapter.ViewHolder>{

    private Context context;
    private List<myOrder> mOrderList;

    static class ViewHolder extends RecyclerView.ViewHolder {

        private ImageView OrderImg;
        private TextView OrderBrand;
        private TextView OrderName;
        private TextView OrderPrice;
        private TextView OrderNum;

        private ViewHolder(View view) {
            super(view);
            OrderImg = (ImageView) view.findViewById(R.id.iv_shop_order_item_img);
            OrderBrand = (TextView) view.findViewById(R.id.tv_shop_order_item_brand);
            OrderName = (TextView) view.findViewById(R.id.tv_shop_order_item_name);
            OrderPrice = (TextView) view.findViewById(R.id.tv_shop_order_item_price);
            OrderNum = (TextView) view.findViewById(R.id.tv_shop_order_item_num);
        }
    }

    public ShopOrderAdapter(Context context, List<myOrder> mOrderList) {
        this.context = context;
        this.mOrderList = mOrderList;
        Log.d(TAG, "ShopOrderAdapter: " + mOrderList.size());
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.shopp_car_order_item, viewGroup, false);
        final ViewHolder holder = new ViewHolder(view);
        //点击事件
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
        final myOrder order = mOrderList.get(i);
        viewHolder.OrderImg.setImageResource(handleData.getResourceByReflect(order.getImgUrl()));
        viewHolder.OrderBrand.setText(order.getBrand());
        viewHolder.OrderName.setText(order.getName());
        viewHolder.OrderPrice.setText("商品价格: ￥" + order.getPrice());
        viewHolder.OrderNum.setText("商品数量：" + order.getNum());
    }

    @Override
    public int getItemCount() {
        return mOrderList.size();
    }
}
